# -*- coding: utf-8 -*-
"""
@Version : 
@Author  : ChenMZ
@Time    : 2025/09/26
@File    : DynamicModel.py
@Desc    : 
@Modify  : 
"""
import time
from collections import deque

from tool.signal_bus import CpuMonitorSignalBus


class CpuPercentageGraphViewModel:
    def __init__(self):
        self._max_deep = 100
        self._point_idx: deque = deque(maxlen=self._max_deep)
        self._data: deque = deque(maxlen=self._max_deep)
        CpuMonitorSignalBus.signal_dynamic_cap_val.connect(self.update_data)

    def _begin_update_model(self):
        pass

    def _finish_update_model(self):
        pass

    # def update_data_array(self, curr_val: array.array):
    #     self._begin_update_model()
    #     self._point_idx += len(curr_val)
    #     self._data.extend(curr_val.tolist())
    #     self._finish_update_model()

    def update_data(self, curr_val: float):
        self._begin_update_model()
        self._point_idx.append(time.perf_counter())
        self._data.append(curr_val)
        # print(self._data)
        self._finish_update_model()

    @property
    def data(self):
        return list(self._data)

    @property
    def time_list(self):
        return self._point_idx


if __name__ == '__main__':
    a = CpuPercentageGraphViewModel()
    a.update_data(123)
    print(a.data)
